﻿//-----------------------------------------------------------------------------
// <copyright file="MainWindowViewModel.cs" company="William E. Kempf">
//     Copyright (c) Peter O'Hanlon.
// </copyright>
//-----------------------------------------------------------------------------

namespace SimpleSilverlight
{
    using Onyx.Command;
    using Onyx.Windows;

    /// <summary>
    /// The <em>View Model</em> for the <see cref="MainWindow"/> <em>View Element</em>.
    /// </summary>
    public class MainWindowViewModel : ViewModel
    {
        /// <summary>
        /// The "TestMessageDisplay" command.
        /// </summary>
        private RelayCommand cmdTestMessageDisplay;

        /// <summary>
        /// Initializes a new instance of the <see cref="MainWindowViewModel"/> class.
        /// </summary>
        /// <param name="view">The view to associate with this instance.</param>
        public MainWindowViewModel(View view)
            : base(view)
        {
        }

        /// <summary>
        /// Gets the TestMessageDisplay command.
        /// </summary>
        /// <value>The TestMessageDisplay command.</value>
        public RelayCommand TestMessageDisplay
        {
            get
            {
                if (this.cmdTestMessageDisplay == null)
                {
                    this.cmdTestMessageDisplay = new RelayCommand(() => this.TestMessageDisplayExecuted());
                }

                return this.cmdTestMessageDisplay;
            }
        }

        /// <summary>
        /// Handles the execution of the <see cref="MainWindowPresenter.TestMessageDisplay"/> command.
        /// </summary>
        private void TestMessageDisplayExecuted()
        {
            IDisplayMessage displayMessage = this.View.GetService(typeof(IDisplayMessage)) as IDisplayMessage;
            if (displayMessage != null)
            {
                var testMessage = this.View.GetService(typeof(ITestMessage)) as ITestMessage;
                if (testMessage != null)
                {
                    displayMessage.ShowMessage(testMessage.TestMessage);
                }
            }
        }
    }
}
